package service;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class MessageHandler {
	private ObjectOutputStream out;
	private ObjectInputStream in;
	
	public MessageHandler(ObjectOutputStream out, ObjectInputStream in){
		this.in = in;
		this.out = out;
	}
	
	public void sendMessage(final String msg) throws IOException {
		out.writeObject(msg);
		out.flush();
	}

	public String readMessage() throws IOException {
        String message = null;
        try {
			message = (String) in.readObject();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return message;
	}
}
